package com.lagou.rpc.server;

import com.lagou.rpc.server.service.UserServiceImpl;
import com.lagou.common.util.RpcService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.PostConstruct;
import java.util.UUID;

@SpringBootApplication
public class ServerBootstrap {

    private static String _hostname;
    private static int _port;

    @Value("${custom.rpc.server.hostname}")
    private String hostname;

    @Value("${custom.rpc.server.port}")
    private int port;

    @PostConstruct
    public void setHostname(){
        _hostname = this.hostname;
    }

    @PostConstruct
    public void setPort(){
        _port = this.port;
    }

    public static void main(String[] args) throws Exception {

        SpringApplication.run(ServerBootstrap.class, args);

        RpcService rpcService = new RpcService(UUID.randomUUID().toString(), _hostname, _port, 0);
        UserServiceImpl.startService(rpcService);
    }
}
